import wx
import random

class MyFrame(wx.Frame):
    name_list = ["tom","jj","xixi","hehe"]
    def __init__(self):
        wx.Frame.__init__(self,None,title="抽奖器",pos=(100,100),size=(400,600))
        # 创建面板
        self.pl = wx.Panel(self,pos=(0,0),size=(400,600))
        self.SetBackgroundColour((200,0,100))
        # 创建静态文本
        self.staticText =  wx.StaticText(self.pl,label=random.choice(self.name_list),pos=(0,50),size=(400,400),style=wx.TE_CENTER)
        self.staticText.SetForegroundColour(wx.RED)

        # 创建字体
        font = wx.Font(46, wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_BOLD)
        self.staticText.SetFont(font)

        # 创建按钮
        self.btn1 = wx.Button(self.pl,label="开始抽奖",pos=(100,200))
        self.btn2 = wx.Button(self.pl, label="结束抽奖", pos=(200,200))
        # 绑定事件
        self.Bind(wx.EVT_BUTTON,self.onClick,self.btn1)
        self.Bind(wx.EVT_BUTTON, self.stop, self.btn2)


    def onClick(self,event):
        # self.staticText.SetLabelText(random.choice(self.name_list))
        self.timer = wx.Timer(self) # 创建一个定时器
        self.Bind(wx.EVT_TIMER,self.update_name,self.timer)
        self.timer.Start(100)

    def stop(self,event):
        self.timer.Stop()

    def update_name(self,event):
        self.staticText.SetLabelText(random.choice(self.name_list))


if __name__ == '__main__':  # python程序主入口
    # 创建程序应用对象
    app = wx.App()
    # 创建窗口
    frm = MyFrame()
    # 显示窗口
    frm.Show()
    # 让窗口一直显示
    app.MainLoop()